﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Cci;
using PartialExpressionCompleter.Util;
using Logging;

namespace PartialExpressionCompleter.Experiment
{
    class MethodForTypeCounter : Experiment
    {
        public override string FileExtension { get { return "mcount"; } }

        public MethodForTypeCounter(IAssembly unit) : base(unit) { }

        public override void RunExperiment()
        {
            foreach (var type in new List<string> {"System.Collections.ArrayList" }
                .Select(CCIUtil.GetType))
            {
                var tstr = type.ToString();
                Logger.PrintLine("# Methods Taking: " + tstr + ": "
                    + CCIUtil.GetAllMethods()
                    .Count(m => m.GetParameterTypes()
                                 .Any(pt => pt.IsAssignableFrom(type, true))
                                && !m.IsOverride()));
                var exact = CCIUtil.GetAllMethods()
                    .Where(m => m.GetParameterTypes()
                                 .Any(pt => pt.ToString().Equals(tstr))
                                && !m.IsOverride())
                    .ToList();
                Logger.PrintLine("# Methods ParamT: " + tstr + ": "
                    + exact.Count);
                foreach (var meth in exact)
                {
                    Logger.PrintLine("Example: " + meth);
                }
                Logger.PrintLine("# supertypes: " + tstr + ": "
                    + type.GetOnlySuperTypes().Count() + ": "
                    + type.GetOnlySuperTypes().CommaSeparated());
            }
        }
    }
}
